<!--

Saherace - Rent a Car

This page shows the inserted attributes of the user as well as all
available cars in the given period of time and stations. 

-->

<!-- Include the soap client connection and the header area of the website -->
<?php include('includes/header.php'); ?>
	
	<?php
	
	//Save the inserted data in a session variable to use them later again
	if(isset($_POST['start_station']))
		$_SESSION['start_station'] 	= $_POST['start_station'];
	
	if(isset($_POST['end_station']))
		$_SESSION['end_station'] 	= $_POST['end_station'];
	
	if(isset($_POST['start_date']))
		$_SESSION['start_date'] 	= $_POST['start_date'];
	
	if(isset($_POST['end_date']))
		$_SESSION['end_date'] 		= $_POST['end_date'];
	
	//Create parameter array for calling webservice method
	$station_id = array('station_id'=> $_SESSION['start_station'], 
						'start_date'=> $_SESSION['start_date'],
						'end_date'=> $_SESSION['end_date']);
						
	//Get all available cars from webservice
	$showAvailableCars = $client->showAvailableCars($station_id);
	
	//Convert station id to station place by method of webservice
	$start_station = $client->getStationById(array('station_id'=> $_SESSION['start_station']));
	$end_station = $client->getStationById(array('station_id'=> $_SESSION['end_station']));

	?>
	
	<!-- Summarize the inserted user data -->
	<p>	
		<table>
			<tr>
				<td width="150"><strong>Anmietung:</strong></td>
				<td><?php $date = new DateTime($_SESSION['start_date']); echo $date->format('d.m.Y H:i') ?> Uhr</td>
			</tr>
			<tr>
				<td></td>
				<td><?php echo $start_station->return->city; ?></td>
			</tr>
		</table>
	</p>
	
	<p>
		<table>
			<tr>
				<td width="150"><strong>R&uumlckgabe:</strong></td>
				<td><?php $date = new DateTime($_SESSION['end_date']); echo $date->format('d.m.Y H:i') ?> Uhr</td>
			</tr>
			<tr>
				<td></td>
				<td><?php echo $end_station->return->city; ?></td>
			</tr>
		</table>
	</p>
	
	<!-- List all available cars -->
	<ul data-role="listview" data-inset="true" data-theme="a">
	<?php
		if (is_object($showAvailableCars) && (count(get_object_vars($showAvailableCars)) > 0)) {
			
			//Show amount of available cars
			echo	 '<li data-role="list-divider">Verf&uuml;gbare Fahrzeuge<span class="ui-li-count">'.sizeof($showAvailableCars->return).'</span></li>';

			//Show each car as a list element
			if (sizeof($showAvailableCars->return) > 1) {
				for($i = 0; $i<sizeof($showAvailableCars->return); $i++){
					//Each list element links to the detail page of the car
					echo '<li><a href="car_details.php?car_id='.$showAvailableCars->return[$i]->id.'">';
					echo '<img class="ui-li-thumb" src="data:image/jpeg;base64,'.base64_encode($showAvailableCars->return[$i]->photo).'" />';			
					echo '<h3>'.$showAvailableCars->return[$i]->brand .' '. $showAvailableCars->return[$i]->carModel.'</h3>';
					echo '<p><strong>'.$showAvailableCars->return[$i]->type .'</strong></p>';
					echo '<p class="ui-li-aside"><strong>'.$showAvailableCars->return[$i]->price .' EUR/Tag</strong></p>';
					echo '</a></li>';
				}
			} else {
				//If there is just one available car
				for($i = 0; $i<sizeof($showAvailableCars->return); $i++){
					//Each list element links to the detail page of the car
					echo '<li><a href="car_details.php?car_id='.$showAvailableCars->return->id.'">';
					echo '<img class="ui-li-thumb" src="data:image/jpeg;base64,'.base64_encode($showAvailableCars->return->photo).'" />';
					echo '<h3>'.$showAvailableCars->return->brand .' '. $showAvailableCars->return->carModel.'</h3>';
					echo '<p><strong>'.$showAvailableCars->return->type .'</strong></p>';
					echo '<p class="ui-li-aside"><strong>'.$showAvailableCars->return->price .' EUR/Tag</strong></p>';
					echo '</a></li>';
				}
			}
		} else {
			//If there is no available car
			echo '<li data-role="list-divider">Verf&uuml;gbare Fahrzeuge<span class="ui-li-count">0</span></li>';
			echo '<li>Keine Fahrzeuge verf&uuml;gbar!</li>';
		}
	?>
	</ul>

<!-- Include the footer area of the website -->
<?php include('includes/footer.php'); ?>